#include <stdlib.h>
#include <iostream>
#include <fstream>

using namespace std;

int main(int argc,char* argv[])
{
	srand(1000);
	string filename = "msnd"+string(argv[1])+"_"+string(argv[2])+".dat";
	int num = atoi(argv[1]);
	int num_comm = atoi(argv[2]);
	cout<<"MSND Generator - output file "<<filename<<endl;
	cout<<"Nodes "<<num<<" Comm "<<num_comm<<endl;
	ofstream msnd_file;
	msnd_file.open(filename.c_str());
	msnd_file<<"data;"<<endl;
	msnd_file<<endl;

	msnd_file<<"set NODES := ";
	for(int i=1;i<=num;i++)
	{
		msnd_file<<"N"<<i<<" ";	
	}
	msnd_file<<";"<<endl<<endl;
	
	msnd_file<<"set ARCS := ";
	for(int i=1;i<=(num*(num-1)/2);i++)
	{
		msnd_file<<"A"<<i<<" ";
	}	
	msnd_file<<";"<<endl<<endl;;
	
	msnd_file<<"param: cost basecap arc_source arc_target :="<<endl;
	int arc_num = 1;
	for(int i=1;i<=num;i++)
	{
		int arc_source = i;
		for(int t=i+1;t<=num;t++)
		{
			int arc_target = t;
			int cost = rand()%10 + 1;
			int basecap = rand()%8 + 1;
			msnd_file<<"\tA"<<arc_num<<" "<<cost<<" "<<basecap<<" "<<arc_source<<" "<<arc_target<<endl;
			arc_num++;
		}
	}	
	msnd_file<<"\t;"<<endl;
	msnd_file<<endl;
	
	msnd_file<<"set COMM := ";
	for(int i=1;i<=num_comm;i++)
	{
		msnd_file<<"C"<<i<<" ";
	}
	msnd_file<<";"<<endl<<endl;

	msnd_file<<"param: comm_source comm_target comm_demand :="<<endl;
	for(int i=1;i<=num_comm;i++)
	{
		int comm_source = rand()%num+1;
		int comm_target = rand()%num+1;
		while(comm_target==comm_source) comm_target = rand()%num+1;
		int comm_demand = (rand()%5);
		msnd_file<<"\tC"<<i<<" "<<comm_source<<" "<<comm_target<<" "<<comm_demand<<endl;
	}	
	msnd_file<<"\t;"<<endl;	

	msnd_file<<endl;	
	msnd_file.close();	
	return 0;
}
